package com.llt.order.service.impl;

import com.llt.order.model.OrderDetail;
import com.llt.order.mapper.OrderDetailMapper;
import com.llt.order.service.IOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.llt.product.api.ProductApi;
import com.llt.product.model.ProductDetail;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author llt
 * @since 2024-05-10
 */
@Slf4j
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    @Resource
    ProductApi productApi;

    @Override
    public OrderDetail getOrderById(Integer orderId) {

        OrderDetail orderDetail = getById(orderId);

        if (orderDetail == null) {
            log.error("不存在该orderId");
            return null;
        }

        ProductDetail productDetail = productApi.getProductInfo(orderDetail.getProductId());

        orderDetail.setProductDetail(productDetail);

        return orderDetail;
    }
}
